#include "objLoader.h"
#include <glut.h>
#include <stdio.h>

static GLint    ImageWidth=500;
static GLint    ImageHeight=500;

objLoader *objData;




void init()
{
	glViewport(0, 0, (GLsizei) ImageWidth, (GLsizei) ImageHeight);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f,(GLfloat) ImageWidth / (GLfloat)ImageHeight , 0.5f, -1000.0f);

	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}

void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	gluLookAt(60,50,-28,12,12,0 ,0,1,0);

	float tt=20;

	glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);

	glScalef(tt,tt,tt);

	glBegin(GL_TRIANGLES);

	for(int i=0; i<objData->faceCount; i++)
	{
		obj_face *o = objData->faceList[i];

		obj_vector* v[3];

		for (int j=0;j<3;j++)
		{
			v[j]=objData->vertexList[o->vertex_index[j]];
		}

		

		for(int j=0; j<3; j++)
		{
			glVertex3f(v[j]->e[0],v[j]->e[1],v[j]->e[2]);
		}



	}

	glEnd();

	glutSwapBuffers();

}


int main(int argc, char **argv)
{
	objData = new objLoader();
	objData->load("bunny.obj");

	printf("Number of vertex normals: %i\n", objData->normalCount);

	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowPosition(100, 100);
	glutInitWindowSize(ImageWidth, ImageHeight);
	glutCreateWindow("FLIP");
	init();
	glutDisplayFunc(display);

	glutMainLoop();


	return 0;

}



